/**
  ******************************************************************************
  * @file    Project/Include File/stm32f05x_regconf_configuration.h
  * @author  Liuhu
  * @version V1.0.0
  * @date    09-June-2013
  * @brief   Library configuration file.
  ******************************************************************************
  */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM32F03X_REGISTER_CONFIGURATION_H  
#define __STM32F03X_REGISTER_CONFIGURATION_H

/* Includes ------------------------------------------------------------------*/
#include "stm8l10x.h"


#define TimeKeyConfirm 2
/* Private typedef -----------------------------------------------------------*/
typedef union  
{
  struct 
  {
    __IO uint16_t bit0: 1;
    __IO uint16_t bit1: 1;
    __IO uint16_t bit2: 1;
    __IO uint16_t bit3: 1;
    __IO uint16_t bit4: 1;
    __IO uint16_t bit5: 1;
    __IO uint16_t bit6: 1;
    __IO uint16_t bit7: 1;
    __IO uint16_t bit8: 1;
    __IO uint16_t bit9: 1;
    __IO uint16_t bit10: 1;
    __IO uint16_t bit11: 1; 
    __IO uint16_t bit12: 1;
    __IO uint16_t bit13: 1;
    __IO uint16_t bit14: 1;
    __IO uint16_t bit15: 1;
  }BIT;
  
  __IO uint16_t Bvalue;
}Union_uint16;


typedef union  
{
  struct 
  {
    __IO uint8_t bit0: 1;
    __IO uint8_t bit1: 1;
    __IO uint8_t bit2: 1;
    __IO uint8_t bit3: 1;
    __IO uint8_t bit4: 1;
    __IO uint8_t bit5: 1;
    __IO uint8_t bit6: 1;
    __IO uint8_t bit7: 1;
  }BIT;
  
  __IO uint8_t Bvalue;
}Union_uint8;

extern  __IO Union_uint8  bflagEvent;

extern __IO Union_uint8 bPADATA;
extern __IO Union_uint8 bPCDATA;
extern __IO Union_uint8 bPDDATA;

extern __IO Union_uint8 bStatusKeyLevel;

extern __IO Union_uint8 bStatusKey;
extern __IO Union_uint8  bStatusKeyTrigger;


/*------------------------------------------------*/
#define flagEvent         bflagEvent.Bvalue
#define flagEncRotating   bflagEvent.BIT.bit0
#define flagEncEnaLast    bflagEvent.BIT.bit1
#define flagEncEnbLast    bflagEvent.BIT.bit2
#define flagCompEvent     bflagEvent.BIT.bit3
#define flagNOBattEvent   bflagEvent.BIT.bit4
#define flagStartEvent    bflagEvent.BIT.bit5
#define flagAdjFirstEvent bflagEvent.BIT.bit6
#define flagSTLEvent 		  bflagEvent.BIT.bit7


#define PADATA  bPADATA.Bvalue
#define PCDATA  bPCDATA.Bvalue
#define PDDATA  bPDDATA.Bvalue

#define PA3     bPADATA.BIT.bit3
#define PD0     bPDDATA.BIT.bit0
#define PC0     bPCDATA.BIT.bit0
#define PC1     bPCDATA.BIT.bit1


#define StatusKey  bStatusKey.Bvalue
#define Key00      bStatusKey.BIT.bit0  //ENA
#define Key01      bStatusKey.BIT.bit1  //ENB
#define Key02      bStatusKey.BIT.bit2  //EN-KEY
#define Key03      bStatusKey.BIT.bit3  //inject key 
#define Key04      bStatusKey.BIT.bit4
#define Key05      bStatusKey.BIT.bit5
#define Key06      bStatusKey.BIT.bit6
#define Key07      bStatusKey.BIT.bit7


#define StatusKeyLevel  bStatusKeyLevel.Bvalue
#define KeyLevel00      bStatusKeyLevel.BIT.bit0
#define KeyLevel01      bStatusKeyLevel.BIT.bit1
#define KeyLevel02      bStatusKeyLevel.BIT.bit2
#define KeyLevel03      bStatusKeyLevel.BIT.bit3
#define KeyLevel04      bStatusKeyLevel.BIT.bit4
#define KeyLevel05      bStatusKeyLevel.BIT.bit5
#define KeyLevel06      bStatusKeyLevel.BIT.bit6
#define KeyLevel07      bStatusKeyLevel.BIT.bit7


#define StatusKeyTrigger  bStatusKeyTrigger.Bvalue
#define KeyTrigger00      bStatusKeyTrigger.BIT.bit0
#define KeyTrigger01      bStatusKeyTrigger.BIT.bit1
#define KeyTrigger02      bStatusKeyTrigger.BIT.bit2
#define KeyTrigger03      bStatusKeyTrigger.BIT.bit3
#define KeyTrigger04      bStatusKeyTrigger.BIT.bit4
#define KeyTrigger05      bStatusKeyTrigger.BIT.bit5
#define KeyTrigger06      bStatusKeyTrigger.BIT.bit6
#define KeyTrigger07      bStatusKeyTrigger.BIT.bit7


//LED0 PB0
//LED7 PC4
//LED4 PC3
//LED5 PA2
//LED6 PB3
//
//LED9 PB1
//LED8 PB2
//LED3 PB4
//LED2 PB5
//LED1 PB6

/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
void Proc_GPIO_Status(void);

bool Gpio_get_key1_val( void );
bool Gpio_get_key2_val( void );
uint8_t Gpio_get_enc_val( void );

void Gpio_set_enc_val( uint8_t val );
void Gpio_LED_Ctrl(uint8_t num);

void GPIO_Config(void);
/* Private functions ---------------------------------------------------------*/

#endif /* __STM32F03X_REGISTER_CONFIGURATION_H */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
